//
//  CaseCell.m
//  International_Hospital
//
//  Created by 张城 on 16/7/7.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "CaseCell.h"

#import "CaseModel.h"

@interface CaseCell ()

@property (nonatomic,weak) UILabel * timeLb;
@property (nonatomic,weak) UILabel * illnessTypeLb;
@property (nonatomic,weak) UILabel * illnessDivideLb;
@property (nonatomic,weak) UILabel * illnessDescribe;
@property (nonatomic,weak) UIView * lineV;
@property (nonatomic,weak) UILabel * lb1;
@property (nonatomic,weak) UILabel * lb2;
@property (nonatomic,weak) UIImageView * imgView;
@property (nonatomic,weak) UIImageView * rb_img;


@end

@implementation CaseCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setup];
    }
    return self;
}

- (void)setup{
    
    
    UIImageView * rb_img = [UIImageView new];
    self.rb_img = rb_img;
    self.rb_img.image = [UIImage imageNamed:@"illness_rb_img_sel.png"];
    [self.contentView addSubview:rb_img];
    
    UIView * lineV = [UIView new];
    self.lineV = lineV;
    lineV.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:lineV];
    
    UILabel * lb1 = [UILabel new];
    self.lb1 = lb1;
    lb1.text = @"疾病类型:";
    lb1.font = FONT(12);
    lb1.textColor = [UIColor blackColor];
    [self.contentView addSubview:lb1];
    
    UILabel * lb2 = [UILabel new];
    self.lb2 = lb2;
    lb2.text = @"基本类型:";
    lb2.font = FONT(12);
    lb2.textColor = [UIColor blackColor];
    [self.contentView addSubview:lb2];
    
    UILabel * timeLb = [UILabel new];
    self.timeLb = timeLb;
    timeLb.font = FONT(12);
    timeLb.font = [UIFont systemFontOfSize:12];
    timeLb.textColor = [UIColor grayColor];
    [self.contentView addSubview:timeLb];
    
    UIImageView * imgView = [[UIImageView alloc]init];
    self.imgView = imgView;
    
    [self.contentView addSubview:imgView];
    
    UILabel * illnessTypeLb = [[UILabel alloc]init];
    illnessTypeLb.textColor = [UIColor grayColor];
    illnessTypeLb.font = FONT(12);
    self.illnessTypeLb = illnessTypeLb;
    [self.contentView addSubview:illnessTypeLb];
    
    UILabel * illnessDivideLb = [[UILabel alloc]init];
    illnessDivideLb.textColor = [UIColor grayColor];
    illnessDivideLb.font = FONT(12);
    self.illnessDivideLb = illnessDivideLb;
    [self.contentView addSubview:illnessDivideLb];
    
    UILabel * illnessDescribe = [[UILabel alloc]init];
    illnessDescribe.textColor = [UIColor grayColor];
    illnessDescribe.font = FONT(12);
    illnessDescribe.numberOfLines = 0;
    self.illnessDescribe = illnessDescribe;
    [self.contentView addSubview:illnessDescribe];
}

- (void)setModel:(CaseModel *)model{
    _model = model;
    
    self.timeLb.text = model.time;
    
    self.imgView.image = model.image;
    
    self.illnessTypeLb.text = [NSString stringWithFormat:@"%@",model.illnessType];
    
    self.illnessDivideLb.text = [NSString stringWithFormat:@"%@",model.illnessDivide];
    self.illnessDescribe.text = model.illnessDescribe;
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.rb_img makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(15);
        make.top.equalTo(0);
        make.size.equalTo(CGSizeMake(20, 20));
    }];
    
    
    [self.timeLb makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(50);
        make.top.equalTo(5);
    }];
    
    NSInteger width = 0;
    if (_model.bol == 1) {
           width = 80;
    }
    if (_model.bol == 0) {
<<<<<<< HEAD
         width = 2;
=======
         width = 0.01;
>>>>>>> 57ad634d11fd6aa9c2a49a0797d636df7d21defe
    }
    
    [self.imgView remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLb.bottom).offset(5);
        make.left.equalTo(self.timeLb.left);
        make.size.equalTo(CGSizeMake(width, 80));
    }];
    
    [self.lb1 remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imgView.top);
        make.left.equalTo(self.imgView.right).offset(5);
    }];
    
    [self.illnessTypeLb makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lb1.right).offset(5);
        make.top.equalTo(self.lb1.top);
    }];
    
    [self.lb2 makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lb1.bottom).offset(5);
        make.left.equalTo(self.lb1.left);
    }];
    
    [self.illnessDivideLb makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lb2.right).offset(5);
        make.top.equalTo(self.lb2.top);
    }];
    
    [self.illnessDescribe makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lb1.left).offset(3);
        make.top.equalTo(self.lb2.bottom).offset(5);
        make.right.equalTo(-5);
    }];
    
    [self.lineV makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(50);
        make.right.equalTo(-5);
        make.bottom.equalTo(0);
        make.height.equalTo(1);
    }];
    
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect{
    UIBezierPath * bezier = [UIBezierPath bezierPath];
    [bezier moveToPoint:CGPointMake(self.rb_img.center.x, 20)];
    [bezier addLineToPoint:CGPointMake(self.rb_img.center.x, 130)];
    [bezier setLineWidth:2];
    [kThemeColor set];
    [bezier stroke];
}







@end

























